<?php

Yii::import('application.vendors.swiftmailer.classes.Swift', true);
Yii::registerAutoloader(array('Swift', 'autoload'));
Yii::import('application.vendors.swiftmailer.swift_init', true);

class Mailer extends CApplicationComponent {
    public $host;
    public $port;
    public $username;
    public $password;

    public function init() {
        parent::init();
    }

    public function sendMail($subject, $from, $to, $body) {
        $message = Swift_Message::newInstance($subject)
                ->setFrom($from)
                ->setTo($to)
                ->setBody($body, 'text/html');

        $transport = Swift_SmtpTransport::newInstance($this->host, $this->port)
                ->setUsername($this->username)
                ->setPassword($this->password);

        $mailer = Swift_Mailer::newInstance($transport);
        
        $mailer->send($message);
    }
}